- [Instructor] MATLAB displays numerical values
as scalar quantities, vectors, and arrays.
That said, visual summaries of your data
can provide insights that the play numbers don't.
In this movie, I will show you how to plot data,
and the output of functions.
I have a blank Command Window,
but what I really need to do is create a script.
So I will go over to the New Script button on the Home tab,
I could also press Control + N,
and click to get a new untitled Editor Window.
For the script, I will define two ranges of variables,
create the plot and then change label and title headings.
So, I will start with a variable I'll just call x,
and set that equal to values in the range starting at 15,
colon, going up by seven, colon, and ending at 64.
I don't want the values to be displayed when the script runs
so I will suppress output with a semicolon.
The corresponding y values, so I have y equal,
will run from 31, colon, with a step of minus two,
colon, ending at 17, and semicolon to suppress.
Now after I press Enter, I can define the plot.
And I'll just do this as a very simple statement.
I'll do plot, left parentheses x, comma y, then a comma,
and rather than use the standard marker,
I do want to assign a marker, so I will type a single quote
to indicate I'm putting in a string,
b, which is the code for blue,
and then a caret, which is the indicator
for an upright triangle with the point at the top.
Type a second single quote to close out the string,
right parentheses and Enter.
Now I can set my axis and label values.
So I'll type axis, left parentheses,
and when you create an axis on a two-dimensional chart,
you define the minimum and then the maximum
for the horizontal or x-axis,
and then minimum and maximum for the vertical or y-axis.
And that's passed as a vector.
So I have axis, left parentheses,
and then to start the vector I need a left square bracket
and I'll have the values of 12 and 70, and then 12 and 40.
Right square bracket to close out the vector,
right parentheses to close out the argument list and Enter.
Now I can set the labels which are just strings,
so say xlabel, left parentheses, and then in single quotes,
milliseconds, right parentheses and then ylabel,
that will be position change in N-M, or nanometers,
single quote, right parentheses,
and then title, and again in single quotes
and parentheses will be position change by time,
single quote, right parentheses and Enter.
Okay, there's my script, everything looks good,
I believe it'll work, so I'll press Control + S to save,
and I will call this moveplot
and press Enter or I could click Save.
Alright, there's my script, I'll go ahead and close it
by clicking the Close Editor button, and then I'll run it
by typing the name of the file, moveplot and Enter.
And you can see that the figure pops up straight away.
If this is the first figure you've created,
then it might take a little bit longer to pop up
because MATLAB needs to update the user interface
to include all of the items that you haven't used before.
And as you can see, I have the horizontal axis label
of milliseconds, position change in nanometers,
which appears here, and then position change by time.
Okay, now I can close out the figure.
And back in the Command Window,
I can double click moveplot.m over in the current folder,
so I can make an edit, so I will right click there.
So let's say that instead of having a range of values for y,
I want to have an equation.
So for example, I could remove the range definition
that I currently have for y and type sqrt,
and then parentheses x, plus eight.
And press Control + S to save.
So the idea, is that rather than having set values,
I'm doing a calculation based on a known rule.
Alright, with that, I can close the Editor Window
and then type moveplot again.
That's the last thing I typed so I'll press an up arrow,
it's highlighted in the command list,
press Enter, and it appears.
And you can see that the values start very small
and increase a bit.
Also note that it looks like my first two values
don't actually appear so I'm going to close out this figure
and reopen moveplot.m by double clicking
and I'm going to change my range definition
so that it goes from zero to 70 and zero to 40.
And again, the first pair of values are minimum
and maximum of horizontal axis, the second pair are
the minimum and maximum for the vertical axis,
and I'll press Control + S, and close the Editor Window,
up arrow, and then when moveplot is highlighted,
press Enter, and there we go, I get my values.
So as you can see, creating a basic plot
doesn't take that long in MATLAB.